<template>
	<view class="black">
		<image class="preview-img" mode="widthFix" :src="cover" @click="showAction"></image>
	</view>
</template>

<script>
	export default ({
		data() {
			return {
				cover: ''
			}
		},
		onLoad(params) {
			this.cover = params.cover
		},
		methods: {
			showAction() {
				var _this = this;
				uni.showActionSheet({
					itemList: ['保存图片到本地'],
					success: function(res) {
						if (res.tapIndex == 0) {
							uni.showLoading({
								title: "正在保存图片中"
							})
							uni.downloadFile({
								url: _this.cover, //仅为示例，并非真实的资源
								success: (result) => {
									//图片的临时保存路径
									var tempFilePath = result.tempFilePath;
									uni.saveImageToPhotosAlbum({
										filePath: tempFilePath,
										success: function() {
											uni.showToast({
												title: "保存成功",
												duration: 2000
											})
										},
										complete: function() {
											uni.hideLoading()
										}
									})
								}
							});
						}
					},
					fail: function(res) {
						console.log(res.errMsg);
					},
					complete: function() {
						uni.hideLoading()
					}
				});
			}
		}
	})
</script>

<style>
	.black {
		width: 100%;
		height: 100%;
		background: black;
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
		position: fixed;
	}
	.preview-img{
		height: 860upx;
	}
</style>
